package tracker.model.tests;

import junit.framework._
import junit.framework.Assert._
import bamboo.util._
import bamboo.util.DateMath._

class TimeSpanTestCase extends TestCase {
  
  def testToString() = {
    assertString("00:42:00.000", TimeSpan.minutes(42))
    assertString("02:41:33.000", TimeSpan.hours(2) + TimeSpan.minutes(41) + TimeSpan.seconds(33))
    
    assertString("00:00:01.999", TimeSpan.seconds(2) - TimeSpan.milliseconds(1))
  }
  
  def testDateMath() {
    val date = new java.util.Date(2007, 7, 21)
    assertEquals(new java.util.Date(2007, 7, 21, 2, 0, 0), date + TimeSpan.hours(2))
    assertEquals(date, (date + TimeSpan.hours(2)) - TimeSpan.minutes(120))
  }
  
  def assertString(expected: String, value: TimeSpan) = {
    assertEquals(expected, value.toString)
  }

}
